Unit BDojoxGridUnit;

{$mode objfpc}{$H+}

Interface

Uses
  Classes, SysUtils, BDojoSessionUnit, BDijitWidgetUnit;

Type

{ BDojoxGridClass }

//** _Grid provides the full set of grid features without any direct connection
//** to a data store. The grid exposes a get function for the grid, or
//** optionally individual columns, to populate cell contents. The grid is
//** rendered based on its structure, an object describing column and cell
//** layout.

BDojoxGridClass = Class(BDijitWidgetClass)
  Private
    bAutoHeight: Boolean;
    bAutoRender: Boolean;
    bAutoWidth: Boolean;
    bClassTag: String;
    bColumnReording: Boolean;
    bDefaultHeight: String;
    bEditable: Boolean;
    bElasticView: Integer;
    bErrorMessage: String;
    bEscapeHTMLInData: Boolean;
    bFastScroll: Boolean;
    bHeaderMenu: BDojoObjectClass;
    bHeight: String;
    bInitialWidth: String;
    bKeepRows: String;
    bLoadingMessage: String;
    bNoDataMessage: String;
    bPlaceholderLabel: String;
    bRowCount: Integer;
    bRowSelector: Boolean;
    bRowsPerPage: Integer;
    bSelectable: Boolean;
    bSelectionMode: String;
    bSingleClickEdit: Boolean;
    Procedure SetAutoHeight(aValue: Boolean);
    Procedure SetAutoRender(aValue: Boolean);
    Procedure SetAutoWidth(aValue: Boolean);
    Procedure SetClassTag(aValue: String);
    Procedure SetColumnReording(aValue: Boolean);
    Procedure SetDefaultHeight(aValue: String);
    Procedure SetEditable(aValue: Boolean);
    Procedure SetElasticView(aValue: Integer);
    Procedure SetErrorMessage(aValue: String);
    Procedure SetEscapeHTMLInData(aValue: Boolean);
    Procedure SetFastScroll(aValue: Boolean);
    Procedure SetHeaderMenu(aValue: BDojoObjectClass);
    Procedure SetHeight(aValue: String);
    Procedure SetInitialWidth(aValue: String);
    Procedure SetKeepRows(aValue: String);
    Procedure SetLoadingMessage(aValue: String);
    Procedure SetNoDataMessage(aValue: String);
    Procedure SetPlaceholderLabel(aValue: String);
    Procedure SetRowCount(aValue: Integer);
    Procedure SetRowSelector(aValue: Boolean);
    Procedure SetRowsPerPage(aValue: Integer);
    Procedure SetSelectable(aValue: Boolean);
    Procedure SetSelectionMode(aValue: String);
    Procedure SetSingleClickEdit(aValue: Boolean);
  Public
    //** If autoHeight is true, grid height is automatically set to fit the
    //** data. If it is an integer, the height will be automatically set to fit
    //** the data if there are fewer than that many rows - and the height will
    //** be set to show that many rows if there are more
    Property AutoHeight: Boolean Read bAutoHeight Write SetAutoHeight;
    //** If autoRender is true, grid will render itself after initialization.
    Property AutoRender: Boolean Read bAutoRender Write SetAutoRender;
    //** If autoWidth is true, grid width is automatically set to fit the data.
    Property AutoWidth: Boolean Read bAutoWidth Write SetAutoWidth;
    //** CSS class applied to the grid's domNode
    Property ClassTag: String Read bClassTag Write SetClassTag;
    //** If set to true, will add drag and drop reordering to views with one
    //** row of columns.
    Property ColumnReording: Boolean Read bColumnReording
      Write SetColumnReording;
    //** default height of the grid, measured in any valid css unit.
    Property DefaultHeight: String Read bDefaultHeight Write SetDefaultHeight;
    //** TODO: description
    Property Editable: Boolean Read bEditable Write SetEditable;
    //** Override defaults and make the indexed grid view elastic, thus filling
    //** available horizontal space.
    Property ElasticView: Integer Read bElasticView Write SetElasticView;
    //** Message that shows when the grid encounters an error loading
    Property ErrorMessage: String Read bErrorMessage Write SetErrorMessage;
    //** This will escape HTML brackets from the data to prevent HTML from
    //** user-inputted data being rendered with may contain JavaScript and
    //** result in XSS attacks. This is true by default, and it is recommended
    //** that it remain true. Setting this to false will allow data to be
    //** displayed in the grid without filtering, and should be only used if it
    //** is known that the data won't contain malicious scripts. If HTML is
    //** needed in grid cells, it is recommended that you use the formatter
    //** function to generate the HTML (the output of formatter functions is
    //** not filtered, even with escapeHTMLInData set to true).
    Property EscapeHTMLInData: Boolean Read bEscapeHTMLInData
      Write SetEscapeHTMLInData;

    //** flag modifies vertical scrolling behavior. Defaults to true but set to
    //** false for slower scroll performance but more immediate scrolling
    //** feedback
    Property FastScroll: Boolean Read bFastScroll Write SetFastScroll;
    //** If set to a dijit.Menu, will use this as a context menu for the grid
    //** headers.
    //TODO: change for BDijitMenuClass
    Property HeaderMenu: BDojoObjectClass Read bHeaderMenu Write SetHeaderMenu;
    //** explicit height of the grid, measured in any valid css unit. This will
    //** be populated (and overridden) if the height: css attribute exists on
    //** the source node.
    Property Height: String Read bHeight Write SetHeight;
    //** A css string to use to set our initial width (only used if autoWidth
    //** is true). The first rendering of the grid will be this width, any
    //** resizing of columns, etc will result in the grid switching to autoWidth
    //** mode. Note, this width will override any styling in a stylesheet or
    //** directly on the node.
    Property InitialWidth: String Read bInitialWidth Write SetInitialWidth;
    //** Number of rows to keep in the rendering cache.
    Property KeepRows: String Read bKeepRows Write SetKeepRows;
    //** Message that shows while the grid is loading
    Property LoadingMessage: String Read bLoadingMessage
      Write SetLoadingMessage;
    //** Message that shows if the grid has no data - wrap it in a span with
    //** class 'dojoxGridNoData' if you want it to be styled similar to the
    //** loading and error messages
    Property NoDataMessage: String Read bNoDataMessage Write SetNoDataMessage;
    //** Label of placeholders to search for in the header menu to replace with
    //** column toggling menu items.
    Property PlaceholderLabel: String Read bPlaceholderLabel
      Write SetPlaceholderLabel;
    //** Number of rows to display.
    Property RowCount: Integer Read bRowCount Write SetRowCount;
    //** If set to true, will add a row selector view to this grid. If set to a
    //** CSS width, will add a row selector of that width to this grid.
    Property RowSelector: Boolean Read bRowSelector Write SetRowSelector;
    //** Number of rows to render at a time.
    Property RowsPerPage: Integer Read bRowsPerPage Write SetRowsPerPage;
    //** Set to true if you want to be able to select the text within the grid.
    Property Selectable: Boolean Read bSelectable Write SetSelectable;
    //** Set the selection mode of grid's Selection. Value must be 'single',
    //** 'multiple', or 'extended'. Default is 'extended'.
    Property SelectionMode: String Read bSelectionMode Write SetSelectionMode;
    //** Single-click starts editing. Default is double-click
    Property SingleClickEdit: Boolean Read bSingleClickEdit Write SetSingleClickEdit;


    //TODO: AdaptHeight;
    //TODO: AdaptWidth;
    //** Add a row to the grid.
    Procedure AddRow;
    //** Use to make multiple changes to rows while queueing row updating.
    //** NOTE: not currently supporting nested begin/endUpdate calls
    Procedure BeginUpdate;
    //** Use after calling beginUpdate to render any changes made to rows.
    Procedure EndUpdate;
End;


    //**
    //**



Implementation

{ BDojoxGridClass }

Procedure BDojoxGridClass.SetAutoHeight(aValue: Boolean);
Begin
  bAutoHeight := aValue;
  SetConfig('autoHeight', aValue);
End;

Procedure BDojoxGridClass.SetAutoRender(aValue: Boolean);
Begin
  bAutoRender := aValue;
  SetConfig('autoRender', aValue);
End;

Procedure BDojoxGridClass.SetAutoWidth(aValue: Boolean);
Begin
  bAutoWidth := aValue;
  SetConfig('autoWidth', aValue);
End;

Procedure BDojoxGridClass.SetClassTag(aValue: String);
Begin
  bClassTag := aValue;
  SetConfig('classTag', aValue);
End;

Procedure BDojoxGridClass.SetColumnReording(aValue: Boolean);
Begin
  bColumnReording := aValue;
  SetConfig('columnReording', aValue);
End;

Procedure BDojoxGridClass.SetDefaultHeight(aValue: String);
Begin
  bDefaultHeight := aValue;
  SetConfig('defaultHeight', aValue);
End;

Procedure BDojoxGridClass.SetEditable(aValue: Boolean);
Begin
  bEditable := aValue;
  SetConfig('editable', aValue);
End;

Procedure BDojoxGridClass.SetElasticView(aValue: Integer);
Begin
  bElasticView := aValue;
  SetConfig('elasticView', aValue);
End;

Procedure BDojoxGridClass.SetErrorMessage(aValue: String);
Begin
  bErrorMessage := aValue;
  SetConfig('errorMessage', aValue);
End;

Procedure BDojoxGridClass.SetEscapeHTMLInData(aValue: Boolean);
Begin
  bEscapeHTMLInData := aValue;
  SetConfig('escapeHTMLInData', aValue);
End;

Procedure BDojoxGridClass.SetFastScroll(aValue: Boolean);
Begin
  bFastScroll := aValue;
  SetConfig('fastScroll', aValue);
End;

Procedure BDojoxGridClass.SetHeaderMenu(aValue: BDojoObjectClass);
Begin
  bHeaderMenu := aValue;
  SetConfig('headerMenu', aValue);
End;

Procedure BDojoxGridClass.SetHeight(aValue: String);
Begin
  bHeight := aValue;
  SetConfig('setHeight', aValue);
End;

Procedure BDojoxGridClass.SetInitialWidth(aValue: String);
Begin
  bInitialWidth := aValue;
  SetConfig('initialWidth', aValue);
End;

Procedure BDojoxGridClass.SetKeepRows(aValue: String);
Begin
  bKeepRows := aValue;
  SetConfig('keepRows', aValue);
End;

Procedure BDojoxGridClass.SetLoadingMessage(aValue: String);
Begin
  bLoadingMessage := aValue;
  SetConfig('loadingMessage', aValue);
End;

Procedure BDojoxGridClass.SetNoDataMessage(aValue: String);
Begin
  bNoDataMessage := aValue;
  SetConfig('noDataMessage', aValue);
End;

Procedure BDojoxGridClass.SetPlaceholderLabel(aValue: String);
Begin
  bPlaceholderLabel := aValue;
  SetConfig('placeholderLabel', aValue);
End;

Procedure BDojoxGridClass.SetRowCount(aValue: Integer);
Begin
  bRowCount := aValue;
  SetConfig('rowCount', aValue);
End;

Procedure BDojoxGridClass.SetRowSelector(aValue: Boolean);
Begin
  bRowSelector := aValue;
  SetConfig('rowSelector', aValue);
End;

Procedure BDojoxGridClass.SetRowsPerPage(aValue: Integer);
Begin
  bRowsPerPage := aValue;
  SetConfig('rowsPerPage', aValue);
End;

Procedure BDojoxGridClass.SetSelectable(aValue: Boolean);
Begin
  bSelectable := aValue;
  SetConfig('selectable', aValue);
End;

Procedure BDojoxGridClass.SetSelectionMode(aValue: String);
Begin
  bSelectionMode := aValue;
  SetConfig('selectionMode', aValue);
End;

Procedure BDojoxGridClass.SetSingleClickEdit(aValue: Boolean);
Begin
  bSingleClickEdit:=aValue;
  SetConfig('singleClickEdit', aValue);
End;

Procedure BDojoxGridClass.AddRow;
Begin
  AddAjax('addRow();');
End;

Procedure BDojoxGridClass.BeginUpdate;
Begin
  AddAjax('beginUpdate();');
End;

Procedure BDojoxGridClass.EndUpdate;
Begin
  AddAjax('endUpdate();');
End;

End.

